//
//  DCNavgiteBar.m
//  Demo
//
//  Created by Kyle on 2022/12/30.
//

#import "DCNavgiteBar.h"


@interface DCNavgiteBar ()

@property (nonatomic, strong) UILabel *titleLabel;

@end
@implementation DCNavgiteBar

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configureUI];
    }
    return self;
}

- (void)configureUI {
//    self.backgroundColor = [UIColor redColor];
    _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_backBtn setImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateNormal];
    _backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [_backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_backBtn];
    [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(41);
        make.bottom.mas_equalTo(0);
        make.width.height.mas_equalTo(44);
    }];
    
    _titleLabel = [UILabel new];
    _titleLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    _titleLabel.font = DCFont_PF_Medium(16);
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.bottom.mas_equalTo(-10);
    }];
}

- (void)upDateBarStyle:(DCNavgiteBarStyle)barStyle {
    if (barStyle == DCNavgiteBarStyleBlack) {
        [_backBtn setImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateNormal];
        _titleLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    } else {
        [_backBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
        _titleLabel.textColor = [UIColor colorWithString:@"#FFFFFF"];
    }
}
- (void)updateTitleName:(NSString *)titleName {
    _titleLabel.text = titleName;
}

- (void)backAction:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(leftBackAction:)]) {
        [self.delegate leftBackAction:sender];
    }
}
@end
